package com.egao.common.manage.school;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.student.constants.StudentSignBlankConstants;
import com.egao.common.module.student.constants.StudentSignConstants;
import com.egao.common.module.student.entity.StudentSignBlank;
import com.egao.common.module.student.entity.vo.StudentSignBlankListVO;
import com.egao.common.module.student.service.StudentSignBlankService;
import com.egao.common.module.system.constants.UserConstants;
import com.egao.common.module.system.service.CollegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 校级空白协议管理
 * @author lym
 */
@Api(tags = "校空白协议管理")
@RestController
@RequestMapping("${api}")
public class SchoolSignBlankController extends BaseController {

    @Autowired
    private StudentSignBlankService studentSignBlankService;
    @Autowired
    private CollegeService collegeService;

    private final String title = "校空白协议管理";

    /**
     * 梁老师工号
     * 校级管理列表 已签约 梁老师不区分学生学历本研
     * 其他正常区分
     */
    private String LIANG_TEACHER = "Z0003981";

    @PreAuthorize("hasAuthority('school:blank:list')")
    @OperLog(value = title, desc = "分页查询空白协议")
    @ApiOperation(value = "分页查询毕业去向")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页多少条", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "category", value = "0全部 1(学院)待审核 2学生待上传 3学院通过待签约 4已签约 5已解约 6作废", required = true, dataType = "int", paramType = "query")
    })
    @GetMapping("/school/blank/page")
    public PageResult<StudentSignBlankListVO> page(HttpServletRequest request) {
        PageParam<StudentSignBlankListVO> pageParam = new PageParam<>(request);
        String degree = null;
        degree = UserConstants.DEGREE_SCOPE_ALL.equals(getLoginUser().getDegreeScope()) ? null : getLoginUser().getDegreeScope();
        pageParam.put("degree", degree);

        String category = pageParam.getString("category");
        if ("4".equals(category)) {
            if (LIANG_TEACHER.equals(getLoginUser().getUsername())) {
                pageParam.put("degree", null);
            }
        }
        return studentSignBlankService.listPage(pageParam);
    }

    @PreAuthorize("hasAuthority('school:blank:list')")
    @ApiOperation(value = "查询所有学院")
    @GetMapping("/school/blank/colleges")
    public JsonResult colleges() {
        return JsonResult.ok().setData(collegeService.listAll(null, ""));
    }

    @PreAuthorize("hasAuthority('school:blank:detail')")
    @OperLog(value = title, desc = "空白协议打印表")
    @ApiPageParam
    @PostMapping("/school/blank/print")
    public JsonResult print(@RequestBody StudentSignBlank studentSignBlank) {
        return studentSignBlankService.print(studentSignBlank.getId(), null);
    }


}
